using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using ApiTest.Api.Entity;
using System.Linq;
using ApiTest.Api.Db;
using ApiTest.Api.Repository;
using ApiTest.Api.Params;
using Microsoft.Extensions.Configuration;
using ApiTest.Api.Utils;
using Microsoft.AspNetCore.Authorization;
using Admin3000.Backend.Api.Params;

namespace ApiTest.Api.Controllers
{
    // [Authorize]
    [ApiController]
    [Route("[controller]")]
    public class LogsController : ControllerBase
    {
        private IConfiguration _configuration;
        private IRepository<AuditInfo>_auditInfoRepository;
        private TokenParameter _tokenParameter;

        public LogsController(IConfiguration configuration, IRepository<AuditInfo>  auditRepository)
        {
            _configuration = configuration;
            _auditInfoRepository = auditRepository;
            _tokenParameter = _configuration.GetSection("TokenParameter").Get<TokenParameter>();
        }

        [HttpGet]
        public dynamic Get()
        {   
            var pageIndex=int.Parse(Request.Query["pageIndex"][0]);
            var pageSize=int.Parse(Request.Query["pageSize"][0]);

            var user = _auditInfoRepository.Table;
            var u=user.Skip((pageIndex-1)*pageSize).Take(pageSize).ToList();
            var res= new
            {
                Code = 1000,
                Data = new{Data =u,Pager=new{pageIndex,pageSize,rowsTotal=user.Count()}},
                Msg = "获取用户列表成功"
            };
            return JsonHelper.Serialize(res);
        }
    }
}